<?php

namespace app\admin\controller;

use app\admin\model\UserList;
use app\admin\model\UserWeb;
use app\admin\service\UserService;
use think\facade\Request;

class User extends Base
{
    protected $middleware = ['AdminCheck', 'AdminPermission'];

    // 列表
    public function index()
    {
        if (Request::isAjax()) {
            return $this->getJson(UserWeb::getList());
        }
        return $this->fetch();
    }

    // 编辑
    public function add()
    {
        if (Request::isAjax()) {
            return $this->getJson(UserService::goAdd());
        }
        return $this->fetch();
    }

    // 编辑
    public function edit($id)
    {
        if (Request::isAjax()) {
            return $this->getJson(UserService::goEdit());
        }
        $data = UserWeb::find($id);
        if ($data) $data['user_birth'] = date('Y-m-d', $data['user_birth']);
        $this->assign('data', $data);
        return $this->fetch();
    }

    public function goStatus()
    {
        return $this->getJson(UserService::goStatus());
    }

    // 删除
    public function goRemove($id)
    {
        return $this->getJson(UserService::goRemove($id));
    }
}